/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package prototype.adaptor;

import java.util.logging.Level;
import java.util.logging.Logger;
import prototype.persistence.pojo.Unit;
import prototype.persistence.pojo.UserHasUnit;
import prototype.runtime.impl.unit.GenericUnit;
import prototype.runtime.interfaces.RuntimeUnit;

/**
 *
 * @author Server
 */
public class RuntimeUnitFactory {

    private static RuntimeUnitFactory instance;

    static {
        instance = new RuntimeUnitFactory();
    }

    public static RuntimeUnitFactory getInstance() {
        return instance;
    }

    public RuntimeUnit newRuntimeUnit(UserHasUnit uhu) {
        RuntimeUnit runtimeUnit;
        try {
            Class a = this.getClass().getClassLoader().loadClass(uhu.getUnit().getClassName());

            runtimeUnit = (RuntimeUnit) a.newInstance();
        } catch (Exception ex) {
            runtimeUnit = new GenericUnit();
        }
        
        runtimeUnit.setUnit(uhu);
        
        return runtimeUnit;
    }
}
